//
//  HMIconView.swift
//  HealthMonitoring
//
//  Created by YTYanK on 27/02/2019.
//  Copyright © 2019 YTYanK. All rights reserved.
//

import UIKit

class HMIconView: UICollectionViewCell {
    open var btn = UIButton()
//    var data = Array<String>()
    open var onClickCallBack: ((HMIconView) -> ())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setSubView()
    }
    
    private func setSubView() {
        self.addSubview(self.btn)
        
        self.btn.setImage(UIImage.init(named: "pl"), for: UIControlState.normal)
        self.btn.setTitle("", for: UIControlState.normal)
        self.btn.imageEdgeInsets =  UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0)
        self.btn.titleEdgeInsets = UIEdgeInsets.init(top: 100, left: -80, bottom: 0, right: 0)
        self.btn.setTitleColor(UIColor.black, for: UIControlState.normal)
        self.btn.topAlign(view: self, predicate: "0")
        self.btn.leadingAlign(view: self, predicate: "0")
        self.btn.trailingAlign(view: self, predicate: "0")
        self.btn.bottomAlign(view: self, predicate: "0")
        self.btn.addTarget(self, action: #selector(clickBtn), for: UIControlEvents.touchUpInside)
    }
    
    open func updateDate(str: String) {
        self.btn.setImage(UIImage.init(named: str), for: UIControlState.normal)
        self.btn.setTitle(str, for: UIControlState.normal)
    }
    
    @objc func clickBtn(sender: UIButton) {
        self.onClickCallBack?(self)
    }
    
    
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}
